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

core: warn when source name defaults to "config" #416

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/promnesia/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pytz

from .cannon import canonify
from .compat import removeprefix


_is_windows = os.name == 'nt'
Expand Down Expand Up @@ -299,9 +300,10 @@ def _guess_name(thing: PreSource) -> str:
guess = thing.__module__

dflt = 'promnesia.sources.'
if guess.startswith(dflt):
# meh
guess = guess[len(dflt):]
guess = removeprefix(guess, prefix=dflt)
if guess == 'config':
# this happens when we define a lambda in config or something without properly wrapping in Source
logger.warning(f'Inferred source name "config" for {thing}. This might be misleading TODO')
return guess


Expand Down Expand Up @@ -331,12 +333,17 @@ def __init__(self, ff: PreSource, *args, src: SourceName='', name: SourceName=''
self.extractor: Extractor = lambda: self.ff(*self.args, **self.kwargs)
if src is not None:
warnings.warn("'src' argument is deprecated, please use 'name' instead", DeprecationWarning)
try:
name_guess = _guess_name(ff)
except:
# todo warn?
name_guess = ''
self.name = name or src or name_guess
if name != '':
self.name = name
elif src != '':
self.name = src
else:
try:
name_guess = _guess_name(ff)
except:
# todo warn?
name_guess = ''
self.name = name_guess

@property
def description(self) -> str:
Expand Down
Loading