Skip to content

Update deprecated 'fn' to 'path' (evdev 1.9.0 removed 'fn') #169

@RedBearAK

Description

@RedBearAK

@joshgoebel

FYI, I just had to do a quick update in xwaykeyz, my fork of xkeysnail/keyszer, due to the apparent removal of a deprecated InputDevice attribute name in an update to evdev that just happened this morning. (Saturday, Feb. 8, 2025)

This will most likely need to be dealt with in all forks of this keymapper. Anyone newly installing them along with evdev 1.9.0 or later will probably run into an AttributeError when attempting to run the keymapper.

There was a deprecation warning in the evdev code (in evdev/device.py), probably for quite some time now.

    @property
    def fn(self):
        msg = "Please use {0}.path instead of {0}.fn".format(self.__class__.__name__)
        warnings.warn(msg, DeprecationWarning, stacklevel=2)
        return self.path

And there's the note about the removal of the deprecated attribute in the evdev change log:

https://python-evdev.readthedocs.io/en/latest/changelog.html#feb-08-2025

Drop deprecated InputDevice.fn (use InputDevice.path instead).

I found that everywhere that device.fn was used needed to be updated to device.path in the keymapper's devices.py module. Including a couple of references that were in a formatting syntax in this, so it was a bit more abstract and needed more than a single simple find/replace operation:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.fn:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.fn:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

That needed to be updated like this, with {1.path:<20} replacing the two {1.fn:<20} instances:

    @staticmethod
    def print_list():
        devices = Devices.all()
        device_format = "{1.path:<20} {1.name:<35} {1.phys}"
        device_lines = [
            device_format.format(n, d) for n, d in enumerate(devices)
        ]
        header_len = max([20 + 35 + 3 + len(x.phys) for x in devices])
        print("-" * header_len)
        print("{:<20} {:<35} {}".format("Device", "Name", "Phys"))
        print("-" * header_len)
        for i, line in enumerate(device_lines):
            dev = devices[i]
            if len(dev.name) > 35:
                fmt = "{1.path:<20} {1.name:<35}"
                print(fmt.format(None, dev))
                print(" " * 57 + dev.phys)
            else:
                print(line)
        print("")

And that is all I know about that.

The fix worked for me after experiencing the AttributeError on a fresh install of Toshy this morning, and a Toshy user quickly confirmed that the updated xwaykeyz 1.4.0 release no longer had the AttributeError when the Toshy installer was run again and cloned the new version of the keymapper.

I'll be cross-posting this to the kinto and xkeysnail GitHub issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp welcomeHelp/contrib is esp welcome

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions