Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Deepti Sharma
    I ama begineer with BeautifulSoup library and I am using it to extract row and column data from a website. But in the code, I am getting "Undefined name row_td"
    I am stuck. Can anyone help?

    from typing import Any

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    import bs4

    from urllib.request import urlopen
    from bs4 import BeautifulSoup

    url = "https://mcs.ciena.com/InetReports/AssemblyHistory/ResultsByAO.asp?SN=NNTMRT112ND8&PN=NTK540BC-820&R=008"
    html = urlopen(url)
    soup = BeautifulSoup(html, 'lxml')
    title = soup.title

    text = soup.get_text()


    rows = soup.find_all('tr')
    for row in rows:
    row_td = row.find_all('td')
    str_cells = str(row_td)
    cleantext = BeautifulSoup(str_cells, "lxml").get_text()

    Its here:
    for row in rows:
    row_td = row.find_all('td')
    Hi all. Anybody know how to run mypy on a directory, but NOT inspect files in the folders above it? For example, I have a folder src that then contains two modules myapp.fonts. When I run mypy src/myapp/fonts it is inspecting every app in my django directory.
    Yang Bo
    Hi guys, how to make sub class method return value compatible with it's base class?
    error: Incompatible return value type (got "AbstractUnitOfWork", expected "SqlAlchemyUnitOfWork")
    Yang Bo
    class AbstractUnitOfWork(abc.ABC):
        def __enter__(self) -> AbstractUnitOfWork:
            return self
    class SqlAlchemyUnitOfWork(AbstractUnitOfWork):
        # True: when in pytest, don't persist db changes
        # False: when in pytest, persist db changes
        is_pytest_non_persistence = True
        def __init__(self, session: scoped_session) -> None:
            self._session = session
        def __enter__(self) -> SqlAlchemyUnitOfWork:
            return super().__enter__()
    Yang Bo

    ok, subclass of type annotation
    for class:

    def func(sub_cls: Type[Base]):

    for instance

    Uow  = TypeVar("Uow", bound=AbstractUnitOfWork)
    def func(instance: Uow):
    Loris Zinsou
    Hi! In one of my projects, there's a specific dataclass I reuse a lot that's semantically an ordered an frozen dataclass, ediclass = partial(dataclass, order=True, frozen=True). I noticed this completely prevents mypy from treating it as a dataclass, which is 99% of mypy errors in this project.
    To my surprise, the decorators for dataclasses are actually hardcoded: https://github.com/python/mypy/blob/master/mypy/plugins/dataclasses.py#L19
    Any idea how I could register a custom dataclass_maker to mypy?
    Does anybody knows anything about the import and\or import order side-effects for mypy? I have working code that mypy comlains abouth with Unexpected keyword argument error. And yet I am unable to reproduce it outside of a big project. I have a hierarchy of dataclassed and if it is all in a single file - mypy agrees and yet once its get distributed across several packages, error emerges.
    Marti Raudsepp
    @Eugene-1984 Have you tried deleting .mypy_cache? Has helped me on rare occasions.
    @intgr No, but this situation reproduces within CI so.. I'll try that regardless, thanks! Now I am trying make the whole project pass with mypy --strictand now metting lots of reexport errors. It is tiresome not to be able to imports to propagate implicitly via all to the top :(
    @intgr removing cache wont help, now I am thinking that the cyclic imports under TYPE_CHECKING hack may be the problem
    Massimo Redaelli
    Suppose I have a complicated Protocol for a callback. I would like to avoid typing all the parameters and return types in every callback definition. Is there a way to say something like @my_protocol def callback(a, b) and have mypy figure out the rest?
    Robot Wei

    Hi! In one of my projects, there's a specific dataclass I reuse a lot that's semantically an ordered an frozen dataclass, ediclass = partial(dataclass, order=True, frozen=True). I noticed this completely prevents mypy from treating it as a dataclass, which is 99% of mypy errors in this project.

    @Hellzed Have you found a solution? From the dataclass_makers constant you provided, I found its usage https://github.com/python/mypy/blob/ec76ccafa757c6d8fbb2c83195170bf75e0ff324/mypy/plugins/default.py#L92, which is get_class_decorator_hook(). IMO chances are a custom plugin providing get_class_decorator_hook() would work.

    Wojciech Niedźwiedź
    good day
    django.core.exceptions.ImproperlyConfigured: django-configurations settings importer wasn't correctly installed. Please use one of the starter functions to install it as mentioned in the docs: https://django-configurations.readthedocs.io/
    that's what happens when I'm running "mypy"
    plugins =
    how do I even debug this? the app runs fine
    Wojciech Niedźwiedź
    trying to introduce mypy to my company's existing codebase, ehh

    I'm having a weird behavior with dict's get method:

    from typing import Dict, Generic, Optional, TypeVar
    K = TypeVar("K")
    X = TypeVar("X")
    # def weird(k: K) -> Optional[X]:
    #     d: Dict[K, X]
    #     return d.get(k, None)
    class NS_gen(Generic[K, X]):
        def __init__(self, ns: Dict[K, X]) -> None:
            self._dict: Dict[K, X] = ns
        def get0(self, key: K) -> Optional[X]:
            return self._dict.get(key, None)

    As is, mypy throws the error: error: Argument 1 to "get" of "Mapping" has incompatible type "K" ; expected "Optional[X]"

    But if the function weird is uncommented, mypy's error disappears... I've tried to find something related to this error in github's issues, but I wasn't able to find something that looks related.

    Ok, nvm, it's probably due to mypy's cache
    Philipp Hahn
    CONTRIBUTING.md talks about using pre-commit, but not on how to set it up: virtualenv -p /usr/bin/python3 .venv && .venv/bin/activate. Still it fails for me when it runs flake8 because of E704 Multiple statements on one line. Creating a tox.ini with [flake8] ignore = E704 fixed it for me. Did I miss something and/or why isn't this conf included somewhere in tox.ini, setup.cfg, pre-commit or wherever?
    Does mypy supports PEP 560 yet? I have error: "MyClass[T]" has no attribute "__orig_bases__" error while the code runs OK for __orig_bases__ exists as per PEP 560 that was accepted!
    Yang Bo
    hi, is there any option for only show "Cannot find implementation or library stub", but not show "Skipping analyzing 'X'"?
    when ignore_missing_imports is False.
    Chris Norman
    Hi, I want to create a dictionary like {name: cls}, where name is of type str, and cls will be a subclass of google.protobuf.message.Message. How can I do this so that mypy will ensure cls will always inherit from google.protobuf.message.Message?
    Marti Raudsepp
    Chris Norman
    Great, thanks. That worked. I forgot the typing module had a Type class, in addition to the lower case builtin version.
    Tomasz Trębski

    hello guys,

    can someone tell if it is possible (in plugin) to create Expr ouf of Type, Something like we have builtins.int and want to create IntExpr?
    or maybe using different words and a little of context: how can I transform OpExpr into what this operation actually produces.
    something like: OpExpr [ 10 ^^ 2]? We have a pow that will create an IntExpr, right?
    how can I do something like that?

    Ref: kornicameister/loguru-mypy#49
    This might give a little bit more context.

    Tanner Stirrat
    class BaseClass:
      _class_defined_by_derived_class: ClassVar[Type[ThatClassBaseType]]
      def get_new_instance(self):
        return self._class_defined_by_derived_class()
    class DerivedClass:
      _class_defined_by_derived_class = ASubclassOfThatClass
    Is there a way to type get_new_instance so that when I call DerivedClass().get_new_instance() it's correctly typed? setting aside the question of whether this class hierarchy makes sense.
    hi, could someone help me with an easy question? why is the revealed type Any after a cast?
    import numpy as np
    from typing import cast, Union
    def foo(x: int) -> None:
        a:Union[np.ndarray]  = cast(np.ndarray, np.zeros(1))
        reveal_type(a) #  Revealed type is 'Any'
    Alexander Ivanov
    please use python/typing
    Iwan Aucamp
    What is the best way to deal with windows specific things in ctypes? https://github.com/aucampia/pallets-click/blob/iwana-typing-000/src/click/_winconsole.py
    e.g. from ctypes import windll # type: ignore
    this whole file is only imported on windows
    so I need to somehow ignore it for linux
    okay I see
    Fabian Becker
    I'm getting "Signature of 'transformer' incompatible with supertype 'GenericQuery'" for the following funcs:
    class GenericQuery:
        def transformer(_arguments: Dict[str, Any], result: Dict, **kwargs) -> Union[Dict, List[Dict]]: ...
    class Subtype(GenericQuery):
        def transformer(parameters: Dict[str, Any], result: Dict, **kwargs) -> Dict: ...
    Can a subtype not return a more specific response?
    Dict still meets the Union[Dict, List[Dict]] criteria..
    Iwan Aucamp
    is there some way to use typing.Literal in python versions before 3.8?
    Thomas Grainger
    @aucampia yes, also the new channel is #python/typing