Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary code of dirsnapshot.py #930

Merged
merged 1 commit into from Nov 30, 2022

Conversation

QuantumEnergyE
Copy link
Contributor

if isinstance(entry, str) is used to distinguish listdir from scandir. Now scandir is used by default, we can delete this code.

@QuantumEnergyE
Copy link
Contributor Author

@BoboTiG PTAL

@BoboTiG
Copy link
Collaborator

BoboTiG commented Nov 30, 2022

Thanks @QuantumEnergyE !

@BoboTiG BoboTiG merged commit cf0a195 into gorakhargosh:master Nov 30, 2022
22 of 23 checks passed
@chadgates
Copy link

@QuantumEnergyE @BoboTiG : now having following error and believe this removal may be the root for it - in version 2.2.1:

Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/threading.py", line 69, in run reraise(*_capture_exception()) File "/usr/local/lib/python3.10/site-packages/sentry_sdk/_compat.py", line 59, in reraise raise value File "/usr/local/lib/python3.10/site-packages/sentry_sdk/integrations/threading.py", line 67, in run return old_run_func(self, *a, **kw) File "/usr/local/lib/python3.10/site-packages/watchdog/observers/api.py", line 148, in run self.queue_events(self.timeout) File "/usr/local/lib/python3.10/site-packages/watchdog/observers/polling.py", line 91, in queue_events new_snapshot = self._take_snapshot() File "/usr/local/lib/python3.10/site-packages/watchdog/observers/polling.py", line 72, in <lambda> self._take_snapshot = lambda: DirectorySnapshot( File "/usr/local/lib/python3.10/site-packages/watchdog/utils/dirsnapshot.py", line 251, in __init__ for p, st in self.walk(path): File "/usr/local/lib/python3.10/site-packages/watchdog/utils/dirsnapshot.py", line 258, in walk paths = [os.path.join(root, entry.name) for entry in self.listdir(root)] File "/usr/local/lib/python3.10/site-packages/watchdog/utils/dirsnapshot.py", line 258, in <listcomp> paths = [os.path.join(root, entry.name) for entry in self.listdir(root)] AttributeError: 'str' object has no attribute 'name'

@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 13, 2023

@chadgates what function do you pass to the listdir argument when instantiating DirectorySnapshot?

@chadgates
Copy link

@BoboTiG : PollingObserverVFS(stat=os.stat, listdir=os.listdir), should I not do that ?

@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 23, 2023

As those arguments are/were the defaults values, not need to set them. Simply remove all of them:

PollingObserverVFS()

@chadgates
Copy link

When I changed code to:
new_observer = PollingObserverVFS()
I get error:
TypeError: PollingObserverVFS.init() missing 2 required positional arguments: 'stat' and 'listdir'

@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 26, 2023

My bad, I didn't check the class itself:

PollingObserverVFS(os.stat, os.scandir)

I don't why those are positional arguments 🤔

@chadgates
Copy link

That did the job! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants