8000 Improve typing references for events · Issue #1040 · gorakhargosh/watchdog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Improve typing references for events #1040
Closed
@fmigneault

Description

@fmigneault

The library defines multiple types such as FileSystemMovedEvent, DirMovedEvent, etc., but does not employ them for on_moved event handler. Instead, it uses the generic FileSystemEvent, which somewhat defeats the purpose of having the event-specific types.

When defining a derived event handler class using the explicit types as below, mypy will complain that it "violates the Liskov substitution principle" as described in https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides, which also makes the definition of handler with the specific types provided inadequate.

def on_moved(self, event: FileSystemMovedEvent | DirMovedEvent): ...

Would it be possible to adjust the types to the specific events expected by each method? The current workaround is to type: ignore, also defining the purpose of defining the types in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0