Skip to content

fix code use black #2610

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
253 changes: 253 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
repos:
- repo: https://github.com/mwouts/jupytext
rev: "v1.16.4b"
hooks:
- id: jupytext
entry: jupytext
language: python
types: [jupyter]
args:
- --from=ipynb
- --to=py:light
- --set-formats=ipynb,py:light
- --quiet
- --sync
- --warn-only
exclude: '.*\.md$'
- repo: https://github.com/PyCQA/docformatter
rev: "eb1df347edd128b30cd3368dddc3aa65edcfac38"
hooks:
- id: docformatter
args: [--in-place, --wrap-descriptions=79, --style=google]
- repo: https://github.com/psf/black.git
rev: "24.10.0"
hooks:
- id: black

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-black
name: nbqa-black
description: Run 'black' on a Jupyter Notebook
entry: nbqa black
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies: [black]
- repo: https://github.com/asottile/pyupgrade
rev: "v3.19.0"
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/pycqa/isort
rev: "5.13.2"
hooks:
- id: isort
entry: isort
args:
- --profile=black
- --float-to-top

- repo: https://github.com/nbQA-dev/nbQA
rev: "1.9.0"
hooks:
- id: nbqa
entry: nbqa blacken-docs
name: nbqa-blacken-docs
alias: nbqa-blacken-docs
additional_dependencies: [blacken-docs]
args:
- --nbqa-md
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-pyupgrade
name: nbqa-pyupgrade
description: Run 'pyupgrade' on a Jupyter Notebook
entry: nbqa pyupgrade
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies: [pyupgrade]
- id: nbqa-isort
name: nbqa-isort
description: Run 'isort' on a Jupyter Notebook
entry: nbqa isort
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies: [isort]
args:
- --profile=black
- --float-to-top

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli
args:
- --ignore-regex=^\s*"image\/(jpeg|png|gif|bmp|tiff)":\s.*
- --ignore-regex=[A-Za-z0-9+/]{100,}
- --skip=*.js,*.html,*.css,*.svg",*.json,*.png,*.jpg,*.yml,*.yaml
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-flake8
args:
- --ignore=E501,E712,W291,F632,E203,F821,F403,W391,F401
- --exclude=.*,__init__.py
name: nbqa-flake8
description: Run 'flake8' on a Jupyter Notebook
entry: nbqa flake8
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies:
- flake8-variables-names
- pep8-naming
- flake8-functions-names

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
args:
- --ignore=E501,E712,W291,F632,E203,F821,F403,W391,F401
- --exclude=.*,__init__.py
additional_dependencies:
- flake8-variables-names
- pep8-naming
- flake8-functions-names

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-mypy
name: nbqa-mypy
description: Run 'mypy' on a Jupyter Notebook
entry: nbqa mypy
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies:
- mypy
- pandas-stubs
- git+https://github.com/numpy/numpy-stubs
- mypy-extensions
- types-requests
- types-PyYAML
- types-setuptools

args:
# - --cache-dir=/dev/null
# - --cache-dir=nul
# - --no-incremental
- --non-interactive
- --install-types
- --explicit-package-bases
- --ignore-missing-imports
- --disallow-untyped-calls
- --disallow-untyped-defs
- --disallow-untyped-decorators
- --strict
- --extra-checks
- --disallow-any-decorated
- --disallow-any-generics
- --local-partial-types
- --pretty
- --force-uppercase-builtins
- --force-union-syntax
- --warn-unreachable
- --warn-redundant-casts
- --warn-return-any
- --disallow-any-explicit



- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
args:
# - --cache-dir=/dev/null
# - --cache-dir=nul
# - --no-incremental
- --non-interactive
- --install-types
- --explicit-package-bases
- --ignore-missing-imports
- --disallow-untyped-calls
- --disallow-untyped-defs
- --disallow-untyped-decorators
- --strict
- --extra-checks
- --disallow-any-decorated
- --disallow-any-generics
- --local-partial-types
- --pretty
- --force-uppercase-builtins
- --force-union-syntax
- --warn-unreachable
- --warn-redundant-casts
- --warn-return-any
- --disallow-any-explicit


additional_dependencies:
- mypy
- pandas-stubs
- git+https://github.com/numpy/numpy-stubs
- mypy-extensions
- types-requests
- types-PyYAML
- types-setuptools

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-pylint
name: nbqa-pylint
description: Run 'pylint' on a Jupyter Notebook
entry: nbqa pylint
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies: [pylint]
args:
- --ignore=no_check*,__init__.py
- --max-line-length=79
- --const-naming-style=any
- --disable=E0401,W0104,R0903,R1721,E1101,E0611,F0002,C0305,C0303,E2515


- repo: https://github.com/pylint-dev/pylint
rev: "v3.3.1"
hooks:
- id: pylint
name: pylint
entry: pylint
language: python
types: [python]
args:
[
"--ignore=no_check*,__init__.py",
"--max-line-length=79",
"--const-naming-style=any",
"--disable=E0401,W0104,R0903,R1721,E1101,E0611,F0002,C0305,line-too-long,C0303,E2515"
]
additional_dependencies: [pylint]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.9.0
hooks:
- id: nbqa-pydocstyle
name: nbqa-pydocstyle
description: Run 'pydocstyle' on a Jupyter Notebook
entry: nbqa pydocstyle
language: python
require_serial: true
types_or: [jupyter, markdown]
additional_dependencies: [pydocstyle]
2 changes: 1 addition & 1 deletion 1 File handle/File handle binary/Update a binary file2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update():
value = pickle.load(File)
found = False
roll = int(input("Enter the roll number of the record"))

for i in value:
if roll == i[0]:
print(f"current name {i[1]}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Amit is a monitor of class XII-A and he stored the record of all
the students of his class in a file named “class.dat”.
Structure of record is [roll number, name, percentage]. His computer
teacher has assigned the following duty to Amit
"""Amit is a monitor of class XII-A and he stored the record of all the
students of his class in a file named “class.dat”. Structure of record is [roll
number, name, percentage]. His computer teacher has assigned the following duty
to Amit.

Write a function remcount( ) to count the number of students who need
remedial class (student who scored less than 40 percent)
Write a function remcount( ) to count the number of students who need remedial
class (student who scored less than 40 percent)
"""


"""
# also find no. of children who got top marks

import pickle
Expand Down
9 changes: 5 additions & 4 deletions 1 File handle/File handle text/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
- Code readability
"""


class Counter:

def __init__(self, text:str) -> None:
def __init__(self, text: str) -> None:
self.text = text

# Define the initial count of the lower and upper case.
Expand All @@ -16,20 +17,20 @@ def __init__(self, text:str) -> None:
self.count()

def count(self) -> None:

for char in self.text:
if char.lower():
self.count_lower += 1
elif char.upper():
self.count_upper += 1

return (self.count_lower, self.count_upper)

def get_total_lower(self) -> int:
return self.count_lower

def get_total_upper(self) -> int:
return self.count_upper

def get_total(self) -> int:
return self.count_lower + self.count_upper
return self.count_lower + self.count_upper
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

import os
import time
file_name= input("Enter the file name to create:- ")

file_name = input("Enter the file name to create:- ")

print(file_name)


def write_to_file(file_name):

if os.path.exists(file_name):
Expand All @@ -15,24 +16,26 @@ def write_to_file(file_name):

while True:
text = input("enter any text to add in the file:- ")
F.write( f"{text}\n" )
F.write(f"{text}\n")
choice = input("Do you want to enter more, y/n").lower()
if choice == "n":
break



def longlines():

with open(file_name, encoding='utf-8') as F:
with open(file_name, encoding="utf-8") as F:
lines = F.readlines()
lines_less_than_50 = list( filter(lambda line: len(line) < 50, lines ) )
lines_less_than_50 = list(filter(lambda line: len(line) < 50, lines))

if not lines_less_than_50:
print("There is no line which is less than 50")
else:
for i in lines_less_than_50:
print(i, end="\t")


if __name__ == "__main__":
write_to_file(file_name)
time.sleep(1)
longlines()
longlines()
2 changes: 1 addition & 1 deletion 1 File handle/File handle text/happy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Take a walk in the park
At the end of the day you are more important than anything else.
Many moments of happiness are waiting
You are amazing!
If you truly believe.
If you truly believe.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
sys.stdout.write("Enter the name of the file")
file = sys.stdin.readline()

with open(file.strip(), ) as F:
with open(file.strip()) as F:

while True:
ch = F.readlines()
for (i) in ch: # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
for (
i
) in (
ch
): # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
print(i, end="")
else:
sys.stderr.write("End of file reached")
break

Loading