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')
type(soup)
bs4.BeautifulSoup
title = soup.title
print(title)
rows = soup.find_all('tr')
print(rows[7:10])
for row in rows:
row_td = row.find_all('td')
print(row_td)
type(row_td)
str_cells = str(row_td)
cleantext = BeautifulSoup(str_cells, "lxml").get_text()
print(cleantext)
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:
super().__init__()
self._session = session
def __enter__(self) -> SqlAlchemyUnitOfWork:
return super().__enter__()
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.
dataclass_maker
to mypy?
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.
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.
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.
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?
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.
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.
from ctypes import windll # type: ignore
class GenericQuery:
@staticmethod
def transformer(_arguments: Dict[str, Any], result: Dict, **kwargs) -> Union[Dict, List[Dict]]: ...
class Subtype(GenericQuery):
@staticmethod
def transformer(parameters: Dict[str, Any], result: Dict, **kwargs) -> Dict: ...