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

File opened without the with statement, critical anti-pattern #119

Open
philipjonsen opened this issue Sep 22, 2023 · 1 comment
Open

File opened without the with statement, critical anti-pattern #119

philipjonsen opened this issue Sep 22, 2023 · 1 comment

Comments

@philipjonsen
Copy link

DESCRIPTION:
Opening a file using with statement is preferred as function open implements the context manager protocol that releases the resource when it is outside of the with block. Not doing so requires you to manually release the resource.

BAD PRACTICE:
f = open('/tmp/.deepsource.toml', 'w')
f.write("config file.")

No f.close() statement: file may remain unaccessible

PREFERRED:
with open('/tmp/.deepsource.toml', 'w') as f:
f.write("config file.")

Use the with statement to open a file in these places:
/Open-Source-Catalog/blob/master/check-catalog.py#L4-L4
Open-Source-Catalog/blob/master/check-catalog.py#L8-L8

@Borsesumit02
Copy link

Hey i want solve this issue, can i ?

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

No branches or pull requests

2 participants