Conversation
| '''`engine.requests` 为 `requests` 请求接口''' | ||
| res = requests.request(*self.args, **self.kw) | ||
| return res | ||
| return requests.request(*self.args, **self.kw) |
There was a problem hiding this comment.
Function engine.requests refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| res = requests.request(*self.args, **self.kw) | ||
| return res | ||
| return requests.request(*self.args, **self.kw) |
There was a problem hiding this comment.
Function engine.httpx refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if not 'headers' in self.kw: | ||
| if 'headers' not in self.kw: | ||
| self.kw['headers'] = {'User-Agent' : get_header()} | ||
| elif not 'User-Agent' in self.kw['headers']: | ||
| elif 'User-Agent' not in self.kw['headers']: | ||
| self.kw['headers'].update({'User-Agent' : get_header()}) | ||
|
|
There was a problem hiding this comment.
Function lupro.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if not res.status_code == 200: | ||
| if res.status_code != 200: | ||
| return ask(self) | ||
| if len(res.content) < self.content: | ||
| return ask(self) | ||
| print(logging(f"{self.filename} {len(res.content)} -----> 请求结束!")) | ||
| print(logging(f"{self.filename} {len(res.content)} -----> 请求结束!")) |
There was a problem hiding this comment.
Function lupro.task.ask refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| path = os.path.join(path,os.path.split(self.filename)[1]+f'.{self.format}') | ||
| if res.apparent_encoding == None: | ||
| path = os.path.join(path, f'{os.path.split(self.filename)[1]}.{self.format}') | ||
| if res.apparent_encoding is None: |
There was a problem hiding this comment.
Function lupro.save_file refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Use x is None rather than x == None (
none-compare)
| def __getattr__(cls, name): | ||
| if not '__general__' in dir(cls): | ||
| def __getattr__(self, name): | ||
| if '__general__' not in dir(self): | ||
| raise NameError("name '__general__' is not defined") | ||
| if hasattr(cls.__general__, name): | ||
| return getattr(cls.__general__, name) | ||
| raise AttributeError(f"method '{name}' is not defined in {cls.__general__}") | ||
| if hasattr(self.__general__, name): | ||
| return getattr(self.__general__, name) | ||
| raise AttributeError(f"method '{name}' is not defined in {self.__general__}") |
There was a problem hiding this comment.
Function inherit.__getattr__ refactored with the following changes:
- The first argument to instance methods should be
self. (instance-method-first-arg-name) - Simplify logical expression using De Morgan identities (
de-morgan)
| def __repr__(cls) -> str: | ||
| return f"<lupros.{cls.__name__} object>" | ||
| def __repr__(self) -> str: | ||
| return f"<lupros.{self.__name__} object>" |
There was a problem hiding this comment.
Function repr.__repr__ refactored with the following changes:
- The first argument to instance methods should be
self. (instance-method-first-arg-name)
| def __getattr__(cls, name): | ||
| if not '__general__' in dir(cls): | ||
| def __getattr__(self, name): | ||
| if '__general__' not in dir(self): | ||
| raise NameError("name '__general__' is not defined") | ||
| if hasattr(cls.__general__, name): | ||
| return getattr(cls.__general__, name) | ||
| if hasattr(self.__general__, name): | ||
| return getattr(self.__general__, name) |
There was a problem hiding this comment.
Function inherit.__getattr__ refactored with the following changes:
- The first argument to instance methods should be
self. (instance-method-first-arg-name) - Simplify logical expression using De Morgan identities (
de-morgan)
|
|
||
| with shelve.open(persistence.shelve.dbfile) as f: | ||
| res = {i:j for i,j in f.items()} | ||
| res = dict(f.items()) |
There was a problem hiding this comment.
Function persistence.shelve.put refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension)
| return func(*args , **kwargs) | ||
| else: | ||
| return None | ||
| return func(*args , **kwargs) if config else None |
There was a problem hiding this comment.
Function reconfig refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if value: | ||
| return value | ||
| else: | ||
| return default | ||
| return value or default |
There was a problem hiding this comment.
Function putdefault refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Replace if statement with if expression (
assign-if-exp)
| if response.apparent_encoding == None: | ||
| if response.apparent_encoding is None: | ||
| return bytescoding(response.content) | ||
| else: | ||
| response.encoding = response.apparent_encoding | ||
| return response.content.decode(response.encoding, 'ignore') No newline at end of file | ||
| response.encoding = response.apparent_encoding | ||
| return response.content.decode(response.encoding, 'ignore') No newline at end of file |
There was a problem hiding this comment.
Function responsecoding refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else) - Use x is None rather than x == None (
none-compare)
Branch
1.0.6refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
1.0.6branch, then run:Help us improve this pull request!