Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Filter jobs with an optional parameter use_regex #4544

@FrancescoDiMuro

Description

@FrancescoDiMuro

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

I want be able to filter the jobs with a partial match of the job names, but the functionget_jobs_by_name doesn't allow it, since it does an absolute comparison between the provided name and the job's name.

Describe the solution you'd like

It would be nice to be able to filter the jobs by their names with the support of regular expressions, so developers can use the same function (get_jobs_by_name), extending its functionality to find jobs matching the pattern in their names.

Describe alternatives you've considered

I considered to use another approach, like getting the list of jobs first, and then filter it with regular expressions, but that's redundant, since everytime this logic has to be applied, a filter step has to be inserted.

Additional context

I've already implemented the functionality in my project, and it seems that it's doing its job:

fromreimportcompile# To put at the top of the moduledefget_jobs_by_name(self,name:str,use_regex:bool=False)->Tuple["Job[CCT]", ...]:"""Returns a tuple of all *pending/scheduled* jobs with the given name that are currently    in the :class:`JobQueue`.    If :obj:`use_regex` parameter is set to :obj:`True`, re.search() function is used to look for    a match with the provided :obj:`name` as pattern on the :obj:`job.name`.    Returns:        Tuple[:class:`Job`]: Tuple of all *pending* or *scheduled* jobs matching the name.    """ifuse_regex:pattern=compile(str(name))returntuple(jobforjobinself.jobs()ifpattern.search(job.name))returntuple(jobforjobinself.jobs()ifjob.name==name)

Since the new parameteruse_regex is set to False as default, the behaviour of this function for actual uses doesn't change, therefore is not a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp