From 94909ab29daca6d0d8656c2a351714b2e5ae4306 Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Sun, 2 Feb 2025 12:12:45 -0500 Subject: [PATCH] Mark Stubs-only packages with [PypiTypes] badge (#10864) * add python typing badge * prettier * Update services/pypi/pypi-typing.service.js Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com> * address comments * rename * fix test * check Typing :: Stubs Only * change test package to typeshed --------- Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com> --- services/pypi/pypi-types.service.js | 14 +++++++++++--- services/pypi/pypi-types.tester.js | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/services/pypi/pypi-types.service.js b/services/pypi/pypi-types.service.js index b0e38ab3283a0..736ffdf06c0d3 100644 --- a/services/pypi/pypi-types.service.js +++ b/services/pypi/pypi-types.service.js @@ -10,7 +10,7 @@ export default class PypiTypes extends PypiBase { get: { summary: 'PyPI - Types', description: - 'Whether the package provides type information, as indicated by the presence of the Typing :: Typed classifier in the package metadata', + 'Type information provided by the package, as indicated by the presence of the `Typing :: Typed` and `Typing :: Stubs Only` classifiers in the package metadata', parameters: pypiGeneralParams, }, }, @@ -18,12 +18,17 @@ export default class PypiTypes extends PypiBase { static defaultBadgeData = { label: 'types' } - static render({ isTyped }) { + static render({ isTyped, isStubsOnly }) { if (isTyped) { return { message: 'typed', color: 'brightgreen', } + } else if (isStubsOnly) { + return { + message: 'stubs', + color: 'brightgreen', + } } else { return { message: 'untyped', @@ -35,6 +40,9 @@ export default class PypiTypes extends PypiBase { async handle({ egg }, { pypiBaseUrl }) { const packageData = await this.fetch({ egg, pypiBaseUrl }) const isTyped = packageData.info.classifiers.includes('Typing :: Typed') - return this.constructor.render({ isTyped }) + const isStubsOnly = packageData.info.classifiers.includes( + 'Typing :: Stubs Only', + ) + return this.constructor.render({ isTyped, isStubsOnly }) } } diff --git a/services/pypi/pypi-types.tester.js b/services/pypi/pypi-types.tester.js index 369596d2d6ff1..450feea729916 100644 --- a/services/pypi/pypi-types.tester.js +++ b/services/pypi/pypi-types.tester.js @@ -9,6 +9,10 @@ t.create('types (no)') .get('/z3-solver.json') .expectBadge({ label: 'types', message: 'untyped' }) +t.create('types (stubs)') + .get('/types-requests.json') + .expectBadge({ label: 'types', message: 'stubs' }) + t.create('types (invalid)') .get('/not-a-package.json') .expectBadge({ label: 'types', message: 'package or version not found' })